home *** CD-ROM | disk | FTP | other *** search
/ Windows Game Programming for Dummies (2nd Edition) / WinGamProgFD.iso / pc / DirectX SDK / DXSDK / bin / DXUtils / AppWizard / DXAppwiz.awx / TEMPLATE / D3D_WIN.H < prev    next >
Encoding:
C/C++ Source or Header  |  2001-10-25  |  12.1 KB  |  332 lines

  1. //-----------------------------------------------------------------------------
  2. // File: $$root$$.h
  3. //
  4. // Desc: Header file $$root$$ sample app
  5. //-----------------------------------------------------------------------------
  6. #ifndef $$FILE_NAME_SYMBOL$$_INCLUDED_
  7. #define $$FILE_NAME_SYMBOL$$_INCLUDED_
  8. $$IF(DPLAY)
  9.  
  10.  
  11.  
  12.  
  13. //-----------------------------------------------------------------------------
  14. // Player context locking defines
  15. //-----------------------------------------------------------------------------
  16. CRITICAL_SECTION g_csPlayerContext;
  17. #define PLAYER_LOCK()                   EnterCriticalSection( &g_csPlayerContext ); 
  18. #define PLAYER_ADDREF( pPlayerInfo )    if( pPlayerInfo ) pPlayerInfo->lRefCount++;
  19. #define PLAYER_RELEASE( pPlayerInfo )   if( pPlayerInfo ) { pPlayerInfo->lRefCount--; if( pPlayerInfo->lRefCount <= 0 ) SAFE_DELETE( pPlayerInfo ); } pPlayerInfo = NULL;
  20. #define PLAYER_UNLOCK()                 LeaveCriticalSection( &g_csPlayerContext );
  21.  
  22. CRITICAL_SECTION g_csWorldStateContext;
  23. #define WORLD_LOCK()                   EnterCriticalSection( &g_csWorldStateContext ); 
  24. #define WORLD_UNLOCK()                 LeaveCriticalSection( &g_csWorldStateContext );
  25. $$ENDIF
  26.  
  27.  
  28.  
  29.  
  30. //-----------------------------------------------------------------------------
  31. // Defines, and constants
  32. //-----------------------------------------------------------------------------
  33. // TODO: change "DirectX AppWizard Apps" to your name or the company name
  34. #define DXAPP_KEY        TEXT("Software\\DirectX AppWizard Apps\\$$root$$")
  35.  
  36. $$IF(SHOW_TRIANGLE)
  37. // Custom D3D vertex format used by the vertex buffer
  38. struct CUSTOMVERTEX
  39. {
  40.     D3DXVECTOR3 position;       // vertex position
  41.     D3DXVECTOR3 normal;         // vertex normal
  42. };
  43.  
  44. #define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ|D3DFVF_NORMAL)
  45.  
  46.  
  47. $$ENDIF // end SHOW_TRIANGLE
  48. $$IF(DPLAY)
  49. // Associate a structure with every network player
  50. struct APP_PLAYER_INFO
  51. {
  52.     // TODO: change as needed
  53.     LONG  lRefCount;                        // Ref count so we can cleanup when all threads 
  54.                                             // are done w/ this object
  55.     DPNID dpnidPlayer;                      // DPNID of player
  56.     TCHAR strPlayerName[MAX_PATH];          // Player name
  57.  
  58. $$IF(ACTIONMAPPER)
  59.     FLOAT fAxisRotateUD;                    // State of axis for this player
  60.     FLOAT fAxisRotateLR;                    // State of axis for this player
  61. $$ELSE
  62.     BOOL  bRotateUp;                       // State of up button or this player
  63.     BOOL  bRotateDown;                     // State of down button or this player
  64.     BOOL  bRotateLeft;                     // State of left button or this player
  65.     BOOL  bRotateRight;                    // State of right button or this player
  66. $$ENDIF
  67. $$IF(DPLAYVOICE)
  68.  
  69.     BOOL  bHalfDuplex;                      // TRUE if player is in half-duplex mode
  70.     BOOL  bTalking;                         // TRUE if player is talking
  71. $$ENDIF
  72.  
  73.     APP_PLAYER_INFO* pNext;
  74.     APP_PLAYER_INFO* pPrev;
  75. };
  76.  
  77.  
  78. $$ENDIF // end DPLAY
  79. $$IF(ACTIONMAPPER)
  80. // DirectInput action mapper reports events only when buttons/axis change
  81. // so we need to remember the present state of relevant axis/buttons for 
  82. // each DirectInput device.  The CInputDeviceManager will store a 
  83. // pointer for each device that points to this struct
  84. struct InputDeviceState
  85. {
  86.     // TODO: change as needed
  87.     FLOAT fAxisRotateLR;
  88.     BOOL  bButtonRotateLeft;
  89.     BOOL  bButtonRotateRight;
  90.  
  91.     FLOAT fAxisRotateUD;
  92.     BOOL  bButtonRotateUp;
  93.     BOOL  bButtonRotateDown;
  94. $$IF(DMUSIC || DSOUND)
  95.  
  96.     BOOL  bButtonPlaySoundButtonDown;
  97. $$ENDIF
  98. };
  99.  
  100.  
  101. $$ENDIF
  102. // Struct to store the current input state
  103. struct UserInput
  104. {
  105. $$IF(KEYBOARD)
  106.     BYTE diks[256];   // DirectInput keyboard state buffer 
  107.  
  108. $$ENDIF
  109.     // TODO: change as needed
  110. $$IF(ACTIONMAPPER)
  111.     FLOAT fAxisRotateUD;
  112.     FLOAT fAxisRotateLR;
  113. $$ELSE // start !ACTIONMAPPER --> (KEYBOARD || !DINPUT)
  114.     BOOL bRotateUp;
  115.     BOOL bRotateDown;
  116.     BOOL bRotateLeft;
  117.     BOOL bRotateRight;
  118. $$ENDIF 
  119. $$IF(DMUSIC || DSOUND)
  120.     BOOL bPlaySoundButtonDown;
  121. $$ENDIF
  122. $$IF(ACTIONMAPPER)
  123.     BOOL bDoConfigureInput;
  124.     BOOL bDoConfigureDisplay;
  125. $$ENDIF
  126. $$IF(DPLAYVOICE)
  127.     BOOL bDoConfigureVoice;
  128. $$ENDIF
  129. };
  130.  
  131.  
  132. $$IF(DPLAY)
  133. //-----------------------------------------------------------------------------
  134. // App specific DirectPlay messages and structures 
  135. //-----------------------------------------------------------------------------
  136.  
  137. // TODO: change or add app specific DirectPlay messages and structures as needed
  138. #define GAME_MSGID_WORLDSTATE    1
  139. #define GAME_MSGID_INPUTSTATE    2
  140. #define GAME_MSGID_HOSTPAUSE     3
  141.  
  142. // Change compiler pack alignment to be BYTE aligned, and pop the current value
  143. #pragma pack( push, 1 )
  144.  
  145. struct GAMEMSG_GENERIC
  146. {
  147.     // One of GAME_MSGID_* IDs so the app knows which GAMEMSG_* struct
  148.     // to cast the msg pointer into.
  149.     WORD nType; 
  150. };
  151.  
  152. struct GAMEMSG_WORLDSTATE : public GAMEMSG_GENERIC
  153. {
  154.     FLOAT fWorldRotX;
  155.     FLOAT fWorldRotY;
  156. };
  157.  
  158. struct GAMEMSG_INPUTSTATE : public GAMEMSG_GENERIC
  159. {
  160. $$IF(ACTIONMAPPER)
  161.     FLOAT fAxisRotateUD;
  162.     FLOAT fAxisRotateLR;
  163. $$ELSE
  164.     BOOL  bRotateUp;   
  165.     BOOL  bRotateDown; 
  166.     BOOL  bRotateLeft; 
  167.     BOOL  bRotateRight;
  168. $$ENDIF
  169. };
  170.  
  171. struct GAMEMSG_HOSTPAUSE : public GAMEMSG_GENERIC
  172. {
  173.     BOOL bHostPause;
  174. };
  175.  
  176. // Pop the old pack alignment
  177. #pragma pack( pop )
  178.  
  179.  
  180. $$ENDIF
  181.  
  182.  
  183. //-----------------------------------------------------------------------------
  184. // Name: class CMyD3DApplication
  185. // Desc: Application class. The base class (CD3DApplication) provides the 
  186. //       generic functionality needed in all Direct3D samples. CMyD3DApplication 
  187. //       adds functionality specific to this sample program.
  188. //-----------------------------------------------------------------------------
  189. class CMyD3DApplication : public CD3DApplication
  190. {
  191.     BOOL                    m_bLoadingApp;          // TRUE, if the app is loading
  192. $$IF(SHOW_TRIANGLE)
  193.     LPDIRECT3DVERTEXBUFFER8 m_pVB;                  // Vextex buffer 
  194. $$ENDIF
  195. $$IF(D3DFONT)
  196.     CD3DFont*               m_pFont;                // Font for drawing text
  197. $$ELSE
  198.     ID3DXFont*              m_pD3DXFont;            // D3DX font    
  199. $$ENDIF
  200. $$IF(SHOW_TEAPOT)
  201.     ID3DXMesh*              m_pD3DXMesh;            // D3DX mesh to store teapot
  202. $$ENDIF
  203.  
  204. $$IF(KEYBOARD)
  205.     LPDIRECTINPUT8          m_pDI;                  // DirectInput object
  206.     LPDIRECTINPUTDEVICE8    m_pKeyboard;            // DirectInput keyboard device
  207. $$ENDIF
  208. $$IF(ACTIONMAPPER)
  209.     CInputDeviceManager*    m_pInputDeviceManager;  // DirectInput device manager
  210.     DIACTIONFORMAT          m_diafGame;             // Action format for game play
  211.     LPDIRECT3DSURFACE8      m_pDIConfigSurface;     // Surface for config'ing DInput devices
  212. $$ENDIF
  213.     UserInput               m_UserInput;            // Struct for storing user input 
  214.  
  215. $$IF(DMUSIC || DSOUND)
  216.     FLOAT                   m_fSoundPlayRepeatCountdown; // Sound repeat timer
  217. $$IF(DMUSIC)
  218.     CMusicManager*          m_pMusicManager;        // DirectMusic manager class
  219.     CMusicSegment*          m_pBounceSound;         // Bounce sound
  220. $$ELSE // start !DMUSIC
  221.     CSoundManager*          m_pSoundManager;        // DirectSound manager class
  222.     CSound*                 m_pBounceSound;         // Bounce sound
  223. $$ENDIF // end DMUSIC
  224.  
  225. $$ENDIF // end (DMUSIC || DSOUND)
  226. $$IF(DPLAY)
  227.     IDirectPlay8Peer*       m_pDP;                  // DirectPlay peer object
  228.     CNetConnectWizard*      m_pNetConnectWizard;    // Connection wizard
  229.     IDirectPlay8LobbiedApplication* m_pLobbiedApp;  // DirectPlay lobbied app 
  230.     BOOL                    m_bWasLobbyLaunched;    // TRUE if lobby launched
  231.     DPNID                   m_dpnidLocalPlayer;     // DPNID of local player
  232.     LONG                    m_lNumberOfActivePlayers;        // Number of players currently in game
  233.     TCHAR                   m_strLocalPlayerName[MAX_PATH];  // Local player name
  234.     TCHAR                   m_strSessionName[MAX_PATH];      // Session name
  235.     TCHAR                   m_strPreferredProvider[MAX_PATH];// Provider string
  236.     APP_PLAYER_INFO         m_PlayInfoList;         // List of players
  237.     APP_PLAYER_INFO*        m_pLocalPlayerInfo;     // APP_PLAYER_INFO struct for local player
  238.     HRESULT                 m_hrNet;                // HRESULT of DirectPlay events
  239.     FLOAT                   m_fWorldSyncTimer;      // Timer for syncing world state between players
  240.     BOOL                    m_bHostPausing;         // Has the host paused the app?
  241.     UserInput               m_CombinedNetworkInput; // Combined input from all network players
  242.  
  243. $$ENDIF
  244. $$IF(DPLAYVOICE)
  245.     CNetVoice*              m_pNetVoice;            // DirectPlay voice helper class
  246.     DVCLIENTCONFIG          m_dvClientConfig;       // Voice client config
  247.     GUID                    m_guidDVSessionCT;      // GUID for chosen voice compression
  248.     BOOL                    m_bNetworkPlayersTalking; // TRUE if any of the network players are talking
  249.     BOOL                    m_bLocalPlayerTalking; // TRUE if the local player is talking
  250.  
  251. $$ENDIF
  252.     FLOAT                   m_fWorldRotX;           // World rotation state X-axis
  253.     FLOAT                   m_fWorldRotY;           // World rotation state Y-axis
  254.  
  255. protected:
  256.     HRESULT OneTimeSceneInit();
  257.     HRESULT InitDeviceObjects();
  258.     HRESULT RestoreDeviceObjects();
  259.     HRESULT InvalidateDeviceObjects();
  260.     HRESULT DeleteDeviceObjects();
  261.     HRESULT Render();
  262.     HRESULT FrameMove();
  263.     HRESULT FinalCleanup();
  264.     HRESULT ConfirmDevice( D3DCAPS8*, DWORD, D3DFORMAT );
  265. $$IF(DPLAY || ACTIONMAPPER)
  266.     VOID    Pause( BOOL bPause );
  267. $$ENDIF
  268.  
  269.     HRESULT RenderText();
  270.  
  271. $$IF(DINPUT)
  272.     HRESULT InitInput( HWND hWnd );
  273. $$ENDIF // end DINPUT
  274.     void    UpdateInput( UserInput* pUserInput );
  275. $$IF(DPLAY)
  276.     HRESULT CombineInputFromAllPlayers( UserInput* pCombinedUserInput );
  277. $$ENDIF // end DPLAY
  278. $$IF(DINPUT)
  279.     void    CleanupDirectInput();
  280. $$ENDIF // end DINPUT
  281.  
  282. $$IF(DMUSIC || DSOUND)
  283.     HRESULT InitAudio( HWND hWnd );
  284.  
  285. $$ENDIF
  286. $$IF(DPLAY)
  287.     HRESULT InitDirectPlay();
  288.     void    CleanupDirectPlay();
  289.     HRESULT ConnectViaDirectPlay();
  290.     HRESULT SendLocalInputIfChanged();
  291.     HRESULT SendWorldStateToAll();
  292.     HRESULT SendPauseMessageToAll( BOOL bPause );
  293.  
  294. $$ENDIF
  295. $$IF(DPLAYVOICE)
  296.     HRESULT InitDirectPlayVoice();
  297.     VOID    UpdateTalkingVariables();
  298.     HRESULT UserConfigVoice();
  299.  
  300. $$ENDIF
  301.     VOID    ReadSettings();
  302.     VOID    WriteSettings();
  303.  
  304. public:
  305.     LRESULT MsgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam );
  306.     CMyD3DApplication();
  307. $$IF(ACTIONMAPPER)
  308.  
  309.     HRESULT InputAddDeviceCB( CInputDeviceManager::DeviceInfo* pDeviceInfo, const DIDEVICEINSTANCE* pdidi );
  310.     static HRESULT CALLBACK StaticInputAddDeviceCB( CInputDeviceManager::DeviceInfo* pDeviceInfo, const DIDEVICEINSTANCE* pdidi, LPVOID pParam );   
  311.     BOOL    ConfigureInputDevicesCB( IUnknown* pUnknown );
  312.     static BOOL CALLBACK StaticConfigureInputDevicesCB( IUnknown* pUnknown, VOID* pUserData );
  313. $$ENDIF
  314. $$IF(DPLAY)
  315.  
  316.     static HRESULT WINAPI StaticDirectPlayMessageHandler( PVOID pvUserContext, DWORD dwMessageId, PVOID pMsgBuffer );
  317.     HRESULT DirectPlayMessageHandler( PVOID pvUserContext, DWORD dwMessageId, PVOID pMsgBuffer );
  318.     static HRESULT WINAPI StaticDirectPlayLobbyMessageHandler( PVOID pvUserContext, DWORD dwMessageId, PVOID pMsgBuffer );
  319.     HRESULT DirectPlayLobbyMessageHandler( PVOID pvUserContext, DWORD dwMessageId, PVOID pMsgBuffer );
  320. $$ENDIF
  321. $$IF(DPLAYVOICE)
  322.  
  323.     static HRESULT WINAPI StaticDirectPlayVoiceServerMessageHandler( PVOID pvUserContext, DWORD dwMessageId, PVOID pMsgBuffer );
  324.     HRESULT DirectPlayVoiceServerMessageHandler( PVOID pvUserContext, DWORD dwMessageId, PVOID pMsgBuffer );
  325.     static HRESULT WINAPI StaticDirectPlayVoiceClientMessageHandler( PVOID pvUserContext, DWORD dwMessageId, PVOID pMsgBuffer );
  326.     HRESULT DirectPlayVoiceClientMessageHandler( PVOID pvUserContext, DWORD dwMessageId, PVOID pMsgBuffer );
  327. $$ENDIF
  328. };
  329.  
  330.  
  331. #endif // !defined($$FILE_NAME_SYMBOL$$_INCLUDED_)
  332.